package com.yanqu.road.server.pb;

import com.yanqu.road.entity.manor.*;
import com.yanqu.road.pb.manor.FishPondProto;
import com.yanqu.road.server.gameplayer.module.manor.fishPondTaskCondition.BaseFishPondCondition;
import com.yanqu.road.server.manger.manor.FishPondMgr;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/10/12 15:49
 */
public class FishPondPb {
    public static FishPondProto.FishingResultMsg.Builder parseFishingResult(FishingResult result) {
        FishPondProto.FishingResultMsg.Builder resultTemp = FishPondProto.FishingResultMsg.newBuilder();
        resultTemp.setEventId(result.getEventId());
        resultTemp.setEventType(result.getEventType());
        resultTemp.setId(result.getId());
        resultTemp.setWeight(result.getWeight());
        resultTemp.setExtendParam(result.getExtendParam());
        resultTemp.setNpcId(result.getNpcId());
        resultTemp.setTextIndex(result.getTextIndex());
        return resultTemp;
    }

    public static List<FedFish> parseFedFishList(List<FishPondProto.FedFishMsg> fedFishList) {
        List<FedFish> list = new ArrayList<>();
        for (FishPondProto.FedFishMsg fedFishMsg : fedFishList) {
            FedFish fedFish = new FedFish();
            fedFish.setFedFishId(fedFishMsg.getFedFishId());
            fedFish.setCount(fedFishMsg.getNum());
            list.add(fedFish);
        }
        return list;
    }

    public static FishPondProto.FishPondDataMsg.Builder parseFishPondData(FishPondData fishPondData, Map<Integer, FishData> fishDataMap, Map<Integer, FishPondSpecialItemData> fishPondSpecialItemDataMap, Map<Long, BaseFishPondCondition> taskConditionMap) {
        FishPondProto.FishPondDataMsg.Builder syncData = FishPondProto.FishPondDataMsg.newBuilder();
        for (FishData fishData : fishDataMap.values()) {
            syncData.addFishData(parseFishData(fishData));
        }
        for (FishPondSpecialItemData specialItemData : fishPondSpecialItemDataMap.values()) {
            syncData.addSpecialItemData(parseSpecialItemData(specialItemData));
        }

        for (BaseFishPondCondition condition : taskConditionMap.values()) {
            FishPondTaskData taskData = condition.getFishPondTaskData();
            syncData.addFishPondTask(parseFishPondTaskData(taskData));
        }
        syncData.setRecoveryTime(fishPondData.getRecoveryTime());
        syncData.setScore(fishPondData.getFishPondScore());
        syncData.setFishPondLv(fishPondData.getFishPondLv());
        syncData.setExp(fishPondData.getExp());
        syncData.setLastRecycleTime(fishPondData.getLastRecycleTime());
        syncData.setAutoFinishTask(fishPondData.isAutoFinishTask());
        return syncData;
    }

    public static FishPondProto.FishPondTaskDataMsg.Builder parseFishPondTaskData(FishPondTaskData taskData) {
        FishPondProto.FishPondTaskDataMsg.Builder temp = FishPondProto.FishPondTaskDataMsg.newBuilder();
        temp.setId(taskData.getId());
        temp.setTaskId(taskData.getTaskId());
        temp.setNpcId(taskData.getNpcId());
        temp.setTextIndex(taskData.getTextIndex());
        temp.setEventId(taskData.getEventId());
        temp.setIsGetReward(taskData.isGetReward());
        temp.setValue(taskData.getValue().longValue());
        temp.setExtendParam(taskData.getExtendParam() == null ? "":taskData.getExtendParam());
        return temp;
    }

    public static FishPondProto.SpecialItemDataMsg.Builder parseSpecialItemData(FishPondSpecialItemData specialItemData) {
        FishPondProto.SpecialItemDataMsg.Builder temp = FishPondProto.SpecialItemDataMsg.newBuilder();
        temp.setSpecialItemId(specialItemData.getSpecialItemId());
        temp.setCount(specialItemData.getCount());
        temp.setIsRead(specialItemData.isReadSample());
        temp.setIsGetUnLockReward(specialItemData.isGetUnLockReward());
        return temp;
    }

    public static FishPondProto.FishDataMsg.Builder parseFishData(FishData fishData) {
        FishPondProto.FishDataMsg.Builder temp = FishPondProto.FishDataMsg.newBuilder();
        temp.setFishId(fishData.getFishId());
        temp.setNum(fishData.getNum());
        temp.setHighestWeight(fishData.getHighestWeight());
        temp.setEquipPatronsId(fishData.getEquipPatronsId());
        temp.setLv(fishData.getLv());
        temp.setIsRead(fishData.isReadSample());
        temp.setIsShow(fishData.isShow());
        temp.setEquipTimes(fishData.getEquipTimes());
        temp.setEquipBuyTimes(fishData.getEquipBuyTimes());
        temp.setIsGetUnLockReward(fishData.isGetUnLockReward());
        temp.setAccFishingCount(fishData.getAccFishingCount());

        for (FishSkillData skill : fishData.getFishSkillDataMap().values()) {
            FishPondProto.FishSkillDataMsg.Builder skillTemp = FishPondProto.FishSkillDataMsg.newBuilder();
            skillTemp.setSkillId(skill.getFishSkillId());
            skillTemp.setLv(skill.getLv());
            skillTemp.setCurExp(skill.getCurExp());
            temp.addSkillData(skillTemp);
        }
        return temp;
    }

    public static FishPondProto.VisitOtherFishPondRespMsg.Builder parseVisitOtherRespMsg(FishPondData fishPondData, Map<Integer, FishData> fishDataMap) {
        FishPondProto.VisitOtherFishPondRespMsg.Builder respMsg = FishPondProto.VisitOtherFishPondRespMsg.newBuilder();
        if (fishPondData != null) {
            respMsg.setFishPondLv(fishPondData.getFishPondLv());
            respMsg.setScore(fishPondData.getFishPondScore());
        } else {
            respMsg.setFishPondLv(FishPondMgr.getInitBadgeLv());
        }
        for (FishData fishData : fishDataMap.values()) {
            respMsg.addFishData(parseFishData(fishData));
        }
        respMsg.setRet(0);
        return respMsg;
    }
}
